﻿using Inovout.Business;
using Inovout.Descriptors;
using System.Windows.Input;
using Inovout.Gui.Wpf.ViewModels;
using Inovout.Portal.Desktop.Workbenchs;

namespace Inovout.Portal.Desktop.Controls
{
    public class RibbonCommandViewModel:BaseViewModel
    {
        private RibbonGroupViewModel group;
        public RibbonGroupViewModel Group
        {
            get { return group; }
        }
        private Function function;
        internal Function Function
        {
            get { return function; }
        }
        public RibbonCommandViewModel(RibbonGroupViewModel group, Function function)
        {
            this.group = group;
            this.function = function;
            this.command = new WorkbenchCommand(group.WorkbenchViewModel,function);
        }

        internal BaseWorkbenchViewModel WorkbenchViewModel
        {
            get { return group.WorkbenchViewModel; }
        }

        public string Header
        {
            get
            {
                ClassDescriptor ownerFunctionGroupClassDescriptor = ClassDescriptor.Create(function.Owner.GetType());
                return ownerFunctionGroupClassDescriptor.GetField(function.Name).Alias;
            }
        }
        public string SmallImage
        {
            get
            {
                return string.Format("/{0};component/Images/{1}16.png"
                  , function.WorkItemType.Assembly.GetName().Name
                  , function.WorkItemType.Name.Substring(0, function.WorkItemType.Name.LastIndexOf("WorkItem")));
            }
        }
        public string LargeImage
        {
            get
            {
                return string.Format("/{0};component/Images/{1}32.png"
                    , function.WorkItemType.Assembly.GetName().Name
                    , function.WorkItemType.Name.Substring(0, function.WorkItemType.Name.LastIndexOf("WorkItem")));
                //return string.Format("pack://application:,,,/{0};component/Images/{1}32.png"
                //    , function.WorkItemType.Assembly.GetName().Name
                //    ,function.WorkItemType.Name.Substring(0,function.WorkItemType.Name.LastIndexOf("WorkItem")));
                //return "pack://application:,,,/Inovout.SoftwareStudio.Business;component/Images/ListProduct32.png";
            }
        }

        private ICommand command;

        public bool IsEnabled
        {
            get { return ExecuteCommand.CanExecute(null); }
        }

        public ICommand ExecuteCommand
        {
            get { return command; }
            set
            {
                if (command != null)
                {
                    command = value;
                    OnPropertyChanged(()=>this.ExecuteCommand);
                }
            }
        }

    }
}
